//
//  ShufflingFigureCell.swift
//  NetWork
//
//  Created by Delin Meng 孟德林 on 2018/10/30.
//  Copyright © 2018 Delin Meng 孟德林. All rights reserved.
//

import UIKit
import Kingfisher

class ShufflingFigureCell: UICollectionViewCell {

    private var imageView:UIImageView = {
        let imageView = UIImageView.init()
        imageView.contentMode = .scaleAspectFill
        imageView.backgroundColor = UIColor.white
        return imageView
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(imageView)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        contentView.addSubview(imageView)
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        layer.shouldRasterize = true
        layer.rasterizationScale = UIScreen.main.scale
        layer.drawsAsynchronously = true
        clipsToBounds = true
        imageView.snp.makeConstraints { (make) in
            make.left.right.bottom.top.equalToSuperview()
        }
    }

    public func setUrl(imageUrl:String?) {
        if let imageStr = imageUrl ,let _ = URL.init(string: imageStr) {
            imageView.wl_setImage(url: imageStr)
        }
    }
    
}

extension UIImageView{
    //可添加options  默认含keepCurrentImageWhileLoading
    //无placeholder
    public func wl_setImage(url:String, options: KingfisherOptionsInfo = KingfisherManager.shared.defaultOptions) {
        var tempOptions = options
        tempOptions.append(.keepCurrentImageWhileLoading)
        self.kf.setImage(with: URL(string: url), options:tempOptions)
    }
}
